//
//  LogoutViewController.swift
//  EasyDana
//
//  Created by mac on 2024/10/18.
//

import UIKit
import RxSwift
class LogoutViewController: UIViewController {

    let logout = PublishSubject<Bool>()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func closeAction(_ sender: Any) {
        self.dismiss(animated: false)
    }
    
    
    @IBAction func exitAction(_ sender: Any) {
        Task {
            do {
                self.showLoading(text: nil)
                let res = try await HTTPManager.default.get(path: Api.logout, param: nil, dataType: [Int].self)
                self.hideLoading()
                if res.code == 0 {
                    UserDefaults.standard.removeObject(forKey: "session_id")
                    //回到首页
                    self.dismiss(animated: false) {
                        self.logout.onNext(true)
                    }
                } else {
                    self.show(toast: res.state)
                }
            } catch {
                self.hideLoading()
            }
        }
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
